// Source File Name:   CPInteger.java

package com.vhly.classfile;

import java.io.*;

// Referenced classes of package com.vhly.classfile:
//            CPEntry

public class CPInteger
        extends CPEntry {

    private int value;
    public static final int tag = 3;
    private static byte buf[] = new byte[4];

    public CPInteger() {
        value = 0;
    }

    public CPInteger(int i) {
        value = i;
    }

    public int getInt() {
        return value;
    }

    public void setInt(int i) {
        value = i;
    }

    public void write(DataOutputStream dout)
            throws IOException {
        dout.write(3);
        ByteArrayOutputStream bout = new ByteArrayOutputStream(4);
        DataOutputStream dout1 = new DataOutputStream(bout);
        dout1.writeInt(value);
        buf = bout.toByteArray();
        dout1.close();
        bout.close();
        dout.write(buf, 0, 4);
    }

    public void read(DataInputStream datainputstream)
            throws IOException {
        datainputstream.read(buf, 0, 4);
        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(buf);
        DataInputStream datainputstream1 = new DataInputStream(bytearrayinputstream);
        value = datainputstream1.readInt();
        datainputstream1.close();
        bytearrayinputstream.close();
    }

    public int getType() {
        return 3;
    }

    /**
     * 比较指定元素是否和自身相等
     *
     * @param e CPEntry
     * @return 0 equals -1 no
     */
    public boolean equalsTo(CPEntry e) {
        CPInteger cpd = (CPInteger) e;
        return this.value == cpd.value;
    }

}